import { createRouter, createWebHistory } from 'vue-router'
import HelloWorld from '../views/HelloWorld.vue'
// import roles from '../views/admin/roles.vue'
import resource from '../views/admin/resource.vue'
import testsse from '../views/testsse.vue'
import login from '../views/admin/login.vue'
import rag from '../views/admin/rag.vue'
// import admin from '../views/admin/admin.vue'

const routes = [{
        path: '/admin',
        name: 'Admin',
        component: () =>
            import ('../views/admin/admin.vue'),
        children: [{
            path: '/roles',
            name: 'Roles',
            component: () =>
                import ('../views/admin/roles.vue'),
            props: true // 允许你将路由参数作为props传递给组件  
        }, {
            path: '/doctor',
            name: 'Doctor',
            component: () =>
                import ('../views/admin/doctor.vue'),
            props: true // 允许你将路由参数作为props传递给组件  
        }]
    }, {
        path: '/login',
        name: 'login',
        component: login
    }, {
        path: '/testsse',
        name: 'testsse',
        component: testsse
    }, {
        path: '/resource',
        name: 'resource',
        component: resource
    }, {
        path: '/',
        name: 'HelloWorld',
        component: HelloWorld
    },
    {
        path: '/user',
        name: 'User',
        component: () =>
            import ('../views/admin/User.vue'),
        children: [{
            path: '/useredit',
            name: 'UserEdit',
            component: () =>
                import ('../views/admin/UserEdit.vue'),
            props: true // 允许你将路由参数作为props传递给组件  
        }]
    }, {
        path: '/rag',
        name: 'rag',
        component: rag
    },

    // 其他路由...  
]

const router = createRouter({
    history: createWebHistory(""),
    routes
})

// router.beforeEach((to, from, next) => {
//     var reslist = ['/login', '/register', '/home']
//     if (reslist.indexOf(to.path) == -1) {
//         var token = localStorage.getItem('token')
//         if (token) {
//             //验证是否在权限列表中
//             var menulist = localStorage.getItem('mpromition')
//             var mlist = JSON.parse(menulist)
//             if (mlist.indexOf(to.path) >= 0) {
//                 next()
//             } else {
//                 alert("无权访问此页面")
//                 next({ "name": 'Login' })
//             }
//         } else {
//             next({ "name": 'Login' })
//         }
//     }
//     next()
// })



export default router